package com.haiya.factory.absfactory.pizza.store;


import com.haiya.factory.absfactory.pizza.product.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class PizzaStore {
    AbstractFactory factory;

    public PizzaStore(AbstractFactory factory) {
        setFactory(factory);
        makePizza();
    }

    public AbstractFactory getFactory() {
        return factory;
    }

    public void setFactory(AbstractFactory factory) {
        this.factory = factory;
    }

    public void makePizza() {
        Pizza pizza = null;
        String orderType = "";

        do {
            orderType = getOrderType();
            pizza = factory.makePizza(orderType);
            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();
        } while (true);
    }

    private String getOrderType() {
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type: ");
            String str = strin.readLine();
            return str;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }
    }
}
